﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model_SSResourceManager
{
   public class ResourceManager
    {
        private readonly IDataBase _dataBase;

        internal ResourceManager(IDataBase dataBase)
        {
            this._dataBase = dataBase;
        }

        public Resource Create()
        {
            return new Resource()
            {
                Id = Guid.NewGuid()
            };
        }

        public bool Add(Resource resource)
        {
            return _dataBase.AddResource(resource);
        }

        public bool Update(Resource resource)
        {
            return _dataBase.UpdateResource(resource);
        }

        public bool Delete(Guid id)
        {
            return _dataBase.DeleteResource(id);
        }

        public bool SetStatus(Guid id, bool _lock)
        {
            Resource resource = this.Get(id);
            resource.Locked = _lock;
            return this.Update(resource);
        }
        
        public Resource Get(Guid id)
        {
            return _dataBase.GetResource(id);
        }
        
        public IEnumerable<Resource> GetAll(bool onlyActive = false)
        {
            return _dataBase.GetAllResource(onlyActive);
        }

        public string GetResourceName(Guid guid)
        {
            return Get(guid).Name;
        }
    }
}
